$(function () {

    var param = location.search;
    var pageNum = 1;
    var pageSize = 5;
    $.ajax({
        type: "get",
        url: "/work/getSalaryList"+ param + "&pageNum=" + pageNum + "&pageSize=" + pageSize,
        dataType: "json",
        success: function (result) {
            generateHtml(result);
            generatePage(result);
        },
        error: function () {
            $("#warning-fade").html("服务请求失败！");
            $("#myModal").modal();
        }
    });

    function generateHtml(result) {
        var html = '';
        $.each(result.data.data, function (i, item) {
            var li = '<div class="job-box bg-white overflow-hidden border rounded mt-4 position-relative overflow-hidden">' +
                '<div class="lable text-center pt-2 pb-2">' +
                '<ul class="list-unstyled best text-white mb-0 text-uppercase">' +
                '<li class="list-inline-item"><i class="mdi mdi-star"></i></li>' +
                '</ul>' +
                '</div>' +
                '<div class="p-4">' +
                '<div class="row align-items-center">' +
                '<div class="col-md-6">' +
                '<div>' +
                '<p class="text-muted mb-0 mo-mb-2"><span class="text-dark">发放日期：</span>' +
                item.gmtCreate +'</p>' +
                '</div>' +
                '</div>' +
                '<div class="col-md-6">' +
                '<div>' +
                '<p class="text-muted mb-0 mo-mb-2"><span class="text-dark">工资：</span>' +
                item.salary + '</p>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            html = html + li;
        });
        var apply_obj = $("#apply-job-item-div");
        apply_obj.html("");
        apply_obj.append(html);
    }

    // 生成页码
    function generatePage(result) {
        Cookies.set('pageNum', result.data.pageNum, {expires: 7, path: ''});
        Cookies.set('jobId', result.data.jobId, {expires: 7, path: ''});
        var page_li_obj = $("#page-ul");
        page_li_obj.html('');
        var total = result.data.total;
        var page_html = '';
        var pre_page_html = '<li class="page-item disabled">' +
            '<a class="page-link" href="" tabindex="-1" aria-disabled="true">' +
            '<i class="mdi mdi-chevron-double-left f-15"></i>' +
            '</a>' +
            '</li>';
        page_html = page_html + pre_page_html;

        // 向上取整
        var num = Math.ceil(total / pageSize);
        for (var i = 1; i <= num; i++) {
            var page_li = '<li class="page-item" id="li_' + i + '"><a class="page-link" onclick="click_page_num(' + i + ')">' + i + '</a></li>';
            if (pageNum == i) {
                page_li = '<li class="page-item active" id="li_' + i + '"><a class="page-link" onclick="click_page_num(' + i + ')">' + i + '</a></li>';
            }
            page_html = page_html + page_li;
        }
        var next_page_html = '<li class="page-item">' +
            '<a class="page-link" onclick="next()">' +
            '<i class="mdi mdi-chevron-double-right f-15"></i>' +
            '</a>' +
            '</li>';
        page_html = page_html + next_page_html;
        page_li_obj.append(page_html);
    }
});